/**
 * 设置http 拦截器js
 */
import axios from 'axios'
import { Loading, Message } from 'element-ui'

axios.defaults.baseURL = 'http://www.laravel.com'
axios.defaults.timeout = 5000
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

var loadinginstace = false

axios.interceptors.request.use(config => {
  loadinginstace = Loading.service({
    fullscreen: true,
    background: 'rgba(0, 0, 0, 0.1)'
  })
  return config
}, error => {
  loadinginstace.close()
  Message.error({
    message: '加载超时'
  })
  return Promise.reject(error)
})
axios.interceptors.response.use(data => {
  loadinginstace.close()
  return data
}, error => {
  loadinginstace.close()
  Message.error({
    message: '加载失败'
  })
  return Promise.reject(error)
})
export default axios
